package com.naton.mydemo.model.repository

import com.naton.common.callback.DataCallback
import com.naton.common.network.ApiErrorModel
import com.naton.common.network.BaseObserver
import com.naton.mydemo.bean.User
import com.naton.mydemo.model.api.RetrofitClient
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * 登录相关
 */
class LoginRepository : BaseRepository(){

    fun login(telephone : String , password : String , callBack : DataCallback<User>){
        RetrofitClient.getInstance().apiService
            .userLogin(telephone, password)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : BaseObserver<User>() {
                override fun onSuccessResult(data: User) {
                   callBack.success(data)
                }

                override fun onErrorResult(statusCode: Int, apiErrorModel: ApiErrorModel) {
                    callBack.failure(statusCode , apiErrorModel)
                }
            })
    }
}